package com.dreamwhale.machinery.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dreamwhale.machinery.config.DataResult;
import com.dreamwhale.machinery.config.StringUtils;
import com.dreamwhale.machinery.entity.TeachingVideo;
import com.dreamwhale.machinery.service.TeachingVideoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 教育视频 前端控制器
 * </p>
 *
 * @author Author
 * @since 2020-08-01
 */
@RestController
@RequestMapping("/teachingVideo")
public class TeachingVideoController {
    @Resource
    private TeachingVideoService teachingVideoService;

    @GetMapping
    public ResponseEntity<DataResult> inquiryTeachingVideo(Integer page, Integer limit, Integer level,
                                       Integer classifyId, String title,String brandId) {

        PageHelper.startPage(page, limit);
        QueryWrapper<TeachingVideo> teachingVideoQueryWrapper = new QueryWrapper<TeachingVideo>().eq("teaching_video_is_del", 0);
        if (level != null) teachingVideoQueryWrapper.eq("teaching_video_vip_level", level);
        if (classifyId != null) teachingVideoQueryWrapper.eq("teaching_video_classify", classifyId);
        if (brandId != null) teachingVideoQueryWrapper.eq("brand_id", brandId);
        if (StringUtils.isNotEmpty(title)) teachingVideoQueryWrapper.like("teaching_video_title", title);
        List<TeachingVideo> teachingVideos = teachingVideoService.list(teachingVideoQueryWrapper);
        return ResponseEntity.ok(new DataResult(new PageInfo<>(teachingVideos)));
    }
}

